package com.trinity.order.refund.controller;

import com.trinity.common.annotation.Log;
import com.trinity.common.core.controller.BaseController;
import com.trinity.common.core.domain.AjaxResult;
import com.trinity.common.core.page.TableDataInfo;
import com.trinity.common.enums.BusinessType;
import com.trinity.common.utils.poi.ExcelUtil;
import com.trinity.order.refund.domain.XcRefundOrder;
import com.trinity.order.refund.service.IXcRefundOrderService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 退款订单Controller
 *
 * @author 董诗攀
 * @date 2024-02-26
 */
@RestController
@RequestMapping("/refund/refund")
public class XcRefundOrderController extends BaseController {
    @Resource
    private IXcRefundOrderService xcRefundOrderService;

    /**
     * 查询退款订单列表
     */
    @PreAuthorize("@ss.hasPermi('refund:refund:list')")
    @RequestMapping(value = "list", method = {RequestMethod.GET})
    public TableDataInfo list(XcRefundOrder xcRefundOrder) {
        startPage();
        List<XcRefundOrder> list = xcRefundOrderService.selectXcRefundOrderList(xcRefundOrder);
        return getDataTable(list);
    }


    /**
     * 获取退款订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('refund:refund:query')")
    @RequestMapping(value = "//{id}", method = {RequestMethod.GET})
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(xcRefundOrderService.selectXcRefundOrderById(id));
    }

    /**
     * 新增退款订单
     */
    @PreAuthorize("@ss.hasPermi('refund:refund:add')")
    @Log(title = "退款订单", businessType = BusinessType.INSERT)
    @RequestMapping(value = "/add", method = {RequestMethod.POST})
    public AjaxResult add(@RequestBody XcRefundOrder xcRefundOrder) {
        return toAjax(xcRefundOrderService.insertXcRefundOrder(xcRefundOrder));
    }

    /**
     * 修改退款订单
     */
    @PreAuthorize("@ss.hasPermi('refund:refund:edit')")
    @Log(title = "退款订单", businessType = BusinessType.UPDATE)
    @RequestMapping(value = "/put", method = {RequestMethod.POST})
    public AjaxResult edit(@RequestBody XcRefundOrder xcRefundOrder) {
        return toAjax(xcRefundOrderService.updateXcRefundOrder(xcRefundOrder));
    }

    /**
     * 删除退款订单
     */
    @PreAuthorize("@ss.hasPermi('refund:refund:remove')")
    @Log(title = "退款订单", businessType = BusinessType.DELETE)
    @RequestMapping(value = "/{ids}/delete", method = {RequestMethod.POST})
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(xcRefundOrderService.deleteXcRefundOrderByIds(ids));
    }

    /**
     * 导出退款订单列表
     */
    @PreAuthorize("@ss.hasPermi('refund:refund:export')")
    @Log(title = "退款订单", businessType = BusinessType.EXPORT)
    @RequestMapping(value = "/export", method = {RequestMethod.POST})
    public void export(HttpServletResponse response, XcRefundOrder xcRefundOrder) {
        List<XcRefundOrder> list = xcRefundOrderService.selectXcRefundOrderList(xcRefundOrder);
        ExcelUtil<XcRefundOrder> util = new ExcelUtil<XcRefundOrder>(XcRefundOrder.class);
        util.exportExcel(response, list, "退款订单数据");
    }
}
